// SKObjectRotate.cpp :
//

#include "stdafx.h"
#include "Transform.h"
#include "SKObjectRotate.h"
#include "Global.h"


// SKObjectRotate

IMPLEMENT_DYNAMIC(CSKObjectRotate, CDialog)

CSKObjectRotate::CSKObjectRotate(CWnd* pParent /*=NULL*/)
	: CDialog(CSKObjectRotate::IDD, pParent)
	, m_editAngle(0)
	, m_pRotatingNode(NULL)
	, m_VerticalAngle(0)
	, m_HorizontalAngle(0)
	, m_iVertical(0)
	, m_iHorizontal(0)
{

}

CSKObjectRotate::~CSKObjectRotate()
{
}

void CSKObjectRotate::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_VERTICALANGLE, m_VerticalAngle);
	DDX_Text(pDX, IDC_EDIT_HORIZONTALANGLE, m_HorizontalAngle);
	DDX_Slider(pDX, IDC_SLIDER_VER, m_iVertical);
	DDX_Slider(pDX, IDC_SLIDER_HOR, m_iHorizontal);
	DDX_Control(pDX, IDC_SLIDER_VER, m_sliderVer);
	DDX_Control(pDX, IDC_SLIDER_HOR, m_sliderHor);
	DDV_MinMaxDouble(pDX, m_VerticalAngle, -90, 90);
	DDV_MinMaxDouble(pDX, m_HorizontalAngle, 0, 360);
}


BEGIN_MESSAGE_MAP(CSKObjectRotate, CDialog)
	ON_BN_CLICKED(IDOK, &CSKObjectRotate::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CSKObjectRotate::OnBnClickedCancel)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_BUTTON_FLIP, &CSKObjectRotate::OnBnClickedButtonFlip)
	ON_BN_CLICKED(IDC_BTN_A, &CSKObjectRotate::OnBnClickedBtnA)
	ON_BN_CLICKED(IDC_BTN_B, &CSKObjectRotate::OnBnClickedBtnB)
	ON_BN_CLICKED(IDC_BTN_C, &CSKObjectRotate::OnBnClickedBtnC)
	ON_BN_CLICKED(IDC_BTN_D, &CSKObjectRotate::OnBnClickedBtnD)
	ON_BN_CLICKED(IDC_BTN_E, &CSKObjectRotate::OnBnClickedBtnE)
	ON_BN_CLICKED(IDC_BTN_F, &CSKObjectRotate::OnBnClickedBtnF)
	ON_BN_CLICKED(IDC_BTN_G, &CSKObjectRotate::OnBnClickedBtnG)
	ON_BN_CLICKED(IDC_BTN_H, &CSKObjectRotate::OnBnClickedBtnH)
	ON_BN_CLICKED(IDC_BTN_I, &CSKObjectRotate::OnBnClickedBtnI)
	ON_BN_CLICKED(IDC_BTN_J, &CSKObjectRotate::OnBnClickedBtnJ)
	ON_BN_CLICKED(IDC_BTN_L, &CSKObjectRotate::OnBnClickedBtnL)
	ON_BN_CLICKED(IDC_BTN_K, &CSKObjectRotate::OnBnClickedBtnK)
	ON_BN_CLICKED(IDC_BTN_M, &CSKObjectRotate::OnBnClickedBtnM)
END_MESSAGE_MAP()


// SKObjectRotate

void CSKObjectRotate::OnBnClickedOk()
{
	// TODO:

	CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CVecBall* pBall = pSKInfo->GetBall();
	CVec ballVec = pBall->GetBallVec();
	m_pRotatingNode->RotateTo(ballVec);

	CSKGlobal::GetMainView()->UpdateView();

	//OnOK();
}

void CSKObjectRotate::OnBnClickedCancel()
{
	// TODO:
	OnCancel();
}

void CSKObjectRotate::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO:

	UpdateData(TRUE);

	switch (pScrollBar->GetDlgCtrlID())
	{
	case IDC_SLIDER_VER:
		{
			m_VerticalAngle = (int)(((double)m_iVertical / 100) * 180) - 90;
		}
		break;

	case IDC_SLIDER_HOR:
		{
			m_HorizontalAngle = (int)(((double)m_iHorizontal / 100) * 360);
		}
		break;
	}

	CSKObjectRotateObject oInput;
	oInput.dVerticalAngle = m_VerticalAngle;
	oInput.dHorizontalAngle = m_HorizontalAngle;

	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition = oInput;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute);
	UpdateData(FALSE);*/

	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

}

void CSKObjectRotate::InitDlg()
{
	CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CVecBall* pBall = pSKInfo->GetBall();
	m_HorizontalAngle = pBall->GetFiAngle() * 180 / SK_PI;
	m_iHorizontal = (int)((m_HorizontalAngle/360) * 100);
	m_sliderHor.SetPos(m_iHorizontal);
	m_VerticalAngle = pBall->GetSitaAngle() * 180 / SK_PI;
	m_iVertical = (int)((m_VerticalAngle - (-90))/180 * 100);
	m_sliderVer.SetPos(m_iVertical);

	UpdateData(FALSE);
}
void CSKObjectRotate::OnBnClickedButtonFlip()
{
}

void CSKObjectRotate::OnBnClickedBtnA()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = m_HorizontalAngle;
	definition.dVerticalAngle = -90;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_VerticalAngle = definition.dVerticalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnB()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = m_HorizontalAngle;
	definition.dVerticalAngle = -45;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_VerticalAngle = definition.dVerticalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnC()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = m_HorizontalAngle;
	definition.dVerticalAngle = 0;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_VerticalAngle = definition.dVerticalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnD()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = m_HorizontalAngle;
	definition.dVerticalAngle = 45;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_VerticalAngle = definition.dVerticalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnE()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = m_HorizontalAngle;
	definition.dVerticalAngle = 90;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_VerticalAngle = definition.dVerticalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnF()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 0;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnG()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 45;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnH()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 90;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnI()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 135;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnJ()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 180;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnL()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 315;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnK()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 225;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}

void CSKObjectRotate::OnBnClickedBtnM()
{
	/*CSKInfo* pSKInfo = CSKGlobal::GetTargetDoc()->GetSKInfo();
	CSKObjectRotateObject& definition = pSKInfo->GetRotateDefinition();
	definition.dHorizontalAngle = 270;
	definition.dVerticalAngle = m_VerticalAngle;

	CALLPIPELINE(CSKFactory::eRotateNode, OnExecute, pSKInfo);
	m_iHorizontal = (int)((definition.dHorizontalAngle/360) * 100);
	m_iVertical = (int)((definition.dVerticalAngle - (-90))/180 * 100);

	m_HorizontalAngle = definition.dHorizontalAngle;
	UpdateData(FALSE);*/
}
